﻿@using Orchard.Comments;
@using Orchard.Comments.Models
@using Orchard.Comments.Settings
@using Orchard.Utility.Extensions;

@{
    CommentsPart commentsPart = Model.ContentPart;
    bool canStillCommentOn = Model.CanStillComment;
    var settings = commentsPart.TypePartDefinition.Settings.GetModel<CommentsPartSettings>();
    var isAuthorized = AuthorizedFor(Permissions.AddComment, Model.ContentItem);
}
@if (!Model.ContentPart.CommentsActive || !canStillCommentOn) {
    if (Model.ContentPart.Comments.Count > 0) {
    <div id="comments">
        <p class="comment-disabled">@T("Comments have been disabled for this content.")</p>
    </div>
    }
}
else if ((settings.MustBeAuthenticated || !isAuthorized) && WorkContext.CurrentUser == null) {
    <p class="info message">@T("You must {0} to comment.", Html.ActionLink(T("log on").ToString(), "LogOn",
                            new { Controller = "Account", Area = "Orchard.Users", ReturnUrl = string.Format("{0}#addacomment", Context.Request.RawUrl) }))</p>
}
else if (WorkContext.CurrentUser != null && !isAuthorized) {
    <div id="comments">
        <p class="comment-disabled">@T("You are not authorized to add a comment.")</p>
    </div>
}
else if (isAuthorized) {
    @Html.ValidationSummary() 
    <span id="comment-form-beacon"></span>
    using (Html.BeginFormAntiForgeryPost(Url.Action("Create", "Comment", new { Area = "Orchard.Comments", ReturnUrl = Context.Request.ToUrlString() }), FormMethod.Post, new { @class = "comment-form" })) {
        if (TempData.ContainsKey("Comments.InvalidCommentEditorShape")) {
            @Display(TempData["Comments.InvalidCommentEditorShape"]);
        }
        else {
            @Display(Model.EditorShape)
        }
    <button class="primaryAction" type="submit">@T("Submit Comment")</button>
    }

}